import {
	getTokenData,
	getPushData,
	checkUserStatus
} from "@/api/common/index.js"
const setPushData = (href) => {
	let userId = uni.getStorageSync("userId")
	getPushData({
		c_url: href,
		u_id: userId || "",
		t_id: uni.getStorageSync("tokenData"),
		v_id: '1.2.0'
	})
}
export const $handleStatistcs = (url="") => {
	var pages = getCurrentPages();  
	var page = url?url:(pages[pages.length - 1]).route;  
	
	const tokenData = uni.getStorageSync("tokenData")
	if (tokenData) {
		setPushData(page)
	} else {
		getTokenData().then(res => {
			if (res.code === 0) {
				uni.setStorageSync("tokenData", res.data)
				setPushData(page)
			}
		})
	}
	// 重置连续点击
	if(page!='pages/shop/index' && page.indexOf('shop/detail')==-1) {
		uni.setStorageSync("userClickNum",0)
		uni.setStorageSync("userClickNum1",0)
	}
	
	// 更新账号信息
	let userId = uni.getStorageSync("userId")
	if (userId) {
		checkUserStatus({
			companyId: JSON.parse(uni.getStorageSync("userInfo")).shopCompany.id,
			userId,
		}).then(res => {
			if (res.code == 0) {
				uni.setStorageSync("userInfo", JSON.stringify(res.data))
			}
		})
	}
}
